#include <bits/stdc++.h>
using namespace std;
void neq2(int a[]){
    if(a[1]==a[2]){
        cout<<a[1]<<endl;
    }else{
        cout<<0<<endl;
    }
}
void neq3(int a[]){
    if(a[1]==a[2]&&a[2]==a[3]){
        cout<<a[1]*2<<endl;
    }else if(a[1]==a[2]||a[2]==a[3]){
        cout<<a[2]<<endl;
    }else if(a[1]==a[3]){
        cout<<a[1]<<endl;
    }else{
        cout<<0<<endl;
    }
}
bool spchk(int a[],int n){
    for(int i=2;i<=n;i++){
        if(a[i]!=a[i-1]){
            return false;
        }
    }
    return true;
}
int solve(int r[],int b[],int rl,int bl){
    int ans=0;
    if(rl>1){
        for(int i=2;i<=rl;i++){
            if(r[i]==r[i-1]){
                ans+=r[i];
            }
        }
    }
    if(bl>1){
        for(int j=rl+bl-1;j>=rl+1;j--){
            if(b[j]==b[j+1]){
                ans+=b[j];
            }
        }
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n+1];
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        int c=0;
        int r[n+1],b[n+1];
        int rl,bl;
        if(n==2){
            neq2(a);
            continue;
        }
        if(n==3){
            neq3(a);
            continue;
        }
        if(spchk(a,n)){
            cout<<a[1]*(n-1)<<endl;
            continue;
        }
        rl=n,bl=0;
        for(int i=1;i<=n;i++){
            r[i]=a[i];
        }
        int kb;
        c=solve(r,b,rl,bl);
        int t=n*(n-1)-1;
        while(t--){
            for(int i=1;i<=rl;i++){
                r[i]=a[i];
            }
            kb=1;
            for(int j=rl;j<=rl+bl;j++){
                b[kb]=a[j];
                kb++;
            }
            c=max(solve(r,b,rl,bl),c);
            rl--;
            bl++;
        }
        cout<<c<<endl;
    }
    return 0;
}
